package com.ruoyi.cloudpc.controller;

import com.ruoyi.cloudpc.domain.CloudTag;
import com.ruoyi.cloudpc.service.ICloudTagService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 标签Controller
 *
 * @author Ten
 * @date 2025-09-13
 */
@RestController
@RequestMapping("/cloudpc/tag")
public class CloudTagController extends BaseController {
    @Autowired
    private ICloudTagService cloudTagService;

    /**
     * 查询标签列表
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(CloudTag cloudTag) {
        startPage();
        List<CloudTag> list = cloudTagService.selectCloudTagList(cloudTag);
        return getDataTable(list);
    }

    /**
     * 导出标签列表
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:tag:export')")
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CloudTag cloudTag) {
        List<CloudTag> list = cloudTagService.selectCloudTagList(cloudTag);
        ExcelUtil<CloudTag> util = new ExcelUtil<CloudTag>(CloudTag.class);
        util.exportExcel(response, list, "标签数据");
    }

    /**
     * 获取标签详细信息
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cloudTagService.selectCloudTagById(id));
    }

    /**
     * 新增标签
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:tag:add')")
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CloudTag cloudTag) {
        return toAjax(cloudTagService.insertCloudTag(cloudTag));
    }

    /**
     * 修改标签
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:tag:edit')")
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CloudTag cloudTag) {
        return toAjax(cloudTagService.updateCloudTag(cloudTag));
    }

    /**
     * 删除标签
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:tag:remove')")
    @Log(title = "标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cloudTagService.deleteCloudTagByIds(ids));
    }
}
